package com.ymatou.iapi.productstock.testcase;

import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productstock.service.ReduceStockListForPreOrderCall;
import com.ymatou.iapi.productstock.service.ReturnProductStockForOrderCall;
import com.ymatou.iapi.productstock.service.ReturnStockListForPreOrderCall;
import com.ymatou.iapi.productstock.service.ReturnStockListForRefundBillCall;
import com.ymatou.productstock.api.parameter.CatalogBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductStockCallService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.model.YmtProductActivityStock;
import com.ymttest.database.model.YmtProductOrderStockLog;
import com.ymttest.database.mongo.ProductActivityStockInfoWapper;
import com.ymttest.database.mongo.ProductStockInfoWapper;
import com.ymttest.database.mongo.StockOperationLogWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.sqlwapper.*;
import com.ymttest.utils.*;
import com.ymttest.utils.constant.JsonBeanFile;
import org.json.JSONObject;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.*;

public class Ts_ReduceStockListForPreOrder {
	//default data
	private static String sellerName = EnvSetup.getData("autotest_sellerName1");
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static int activityStartId = Integer.parseInt(EnvSetup.getData("productActivityStartId"));
	private static String activityUser = EnvSetup.getData("admin");
	private static String activityPswd = EnvSetup.getData("password");
	
		

	
	//private static ReduceProductStockForOrderCall reduceProductStockForOrderCall;
	private static ReturnProductStockForOrderCall retutnProductStockForOrderCall = new ReturnProductStockForOrderCall();
	
	private static ReturnStockListForPreOrderCall returnStockListForPreOrderCall = new ReturnStockListForPreOrderCall();
	
	private static ReturnStockListForRefundBillCall returnStockListForRefundBillCall = new ReturnStockListForRefundBillCall();
	
	private static ReduceStockListForPreOrderCall reduceStockListForPreOrderCall = new ReduceStockListForPreOrderCall();

	
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("扣减库存服务");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(reduceStockListForPreOrderCall.getOpurl());
	}
	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	//扣减库存，普通现货商品，不在活动中
	//reduceStockListForPreOrderCall  / retutnProductStockForOrderCall
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReduceStockListForPreOrder_001() {
		Logger.start(true, "普通现货商品，不在活动中,扣减库存，返还库存");
		try{
			//Test date
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			
			String catalogsId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4)); 
			int OrderId = Math.abs(TestDataManager.getRandomIntNum(8)); 
			int buyNum = -2;
			int returnNum = 2;
			
		
			//===================================================================================================================
			//扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> updateMap = new HashMap<String, Object>();
			updateMap.put("CatalogList[0]->CatalogId", catalogsId);
			updateMap.put("CatalogList[0]->CatalogType", 0);
			updateMap.put("CatalogList[0]->ProductId", productId);
			updateMap.put("CatalogList[0]->SellerId", sellerId);
			updateMap.put("CatalogList[0]->BuyCount", -1*buyNum);
			updateMap.put("CatalogList[0]->BuyerId", BuyerId);
			updateMap.put("CatalogList[0]->PreOrderId", OrderId);
			updateMap.put("CatalogList[0]->IsLiveProduct", false);
			
			JSONObject retBean = reduceStockListForPreOrderCall.callAndGetReturnData(updateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals((catalogNum+buyNum), ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductOrderStockLog 
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper().selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",buyNum,//扣减库存数量
															"activityId",0); //活动Id
															
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
		
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum+buyNum),new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",buyNum,//扣减库存数量
																		"ActivityId",0); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60,"AddTime");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum+buyNum);
				stockBean1.setStockType(0);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
			
			
			//===================================================================================================================
			//返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogStockList[0]->ActivityId", 0);
			returnUpdateMap.put("CatalogStockList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogId", catalogsId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogType", 0);
			returnUpdateMap.put("CatalogStockList[0]->OrderId", OrderId);
			returnUpdateMap.put("CatalogStockList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogStockList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogStockList[0]->StockNum", returnNum);
			returnUpdateMap.put("CatalogStockList[0]->IsLiveProduct", false);
			
			JSONObject retutnproductstockBean = JsonBeanHelper.getJsonBean(JsonBeanFile.returnproductstockforordercalltpl);
			JsonBeanHelper.updateJsonBean(retutnproductstockBean, returnUpdateMap);
			retutnProductStockForOrderCall.setData(retutnproductstockBean);
			retutnProductStockForOrderCall.callService();
			Logger.verifyEquals(true, retutnProductStockForOrderCall.getReturnData().contains("ok"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",returnNum,//返还库存数量
															"activityId",0); //活动Id
															
			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
		
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals(catalogNum,new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",returnNum,//扣减库存数量
																		"ActivityId",0); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	
	
	//扣减库存，普通现货商品，不在活动中
	//reduceStockListForPreOrderCall  / returnStockListForPreOrderCall
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReduceStockListForPreOrder_001_2() {
		Logger.start(true, "普通现货商品，不在活动中,扣减库存，返还库存");
		try{
			//Test date
			String productId = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, null).getJSONObject("Data").getString("ProductID");
			
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			
			String catalogsId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4)); 
			int OrderId = Math.abs(TestDataManager.getRandomIntNum(8)); 
			int buyNum = -2;
			int returnNum = 2;
			
		
			//===================================================================================================================
			//扣减库存
			Logger.comment("扣减setProductInActivityId");
			Map<String, Object> updateMap = new HashMap<String, Object>();
			updateMap.put("CatalogList[0]->CatalogId", catalogsId);
			updateMap.put("CatalogList[0]->CatalogType", 0);
			updateMap.put("CatalogList[0]->ProductId", productId);
			updateMap.put("CatalogList[0]->SellerId", sellerId);
			updateMap.put("CatalogList[0]->BuyCount", -1*buyNum);
			updateMap.put("CatalogList[0]->BuyerId", BuyerId);
			updateMap.put("CatalogList[0]->PreOrderId", OrderId);
			updateMap.put("CatalogList[0]->IsLiveProduct", false);
			
			JSONObject retBean = reduceStockListForPreOrderCall.callAndGetReturnData(updateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals((catalogNum+buyNum), ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductOrderStockLog 
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper().selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",buyNum,//扣减库存数量
															"activityId",0); //活动Id
															
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
		
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum+buyNum),new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",buyNum,//扣减库存数量
																		"ActivityId",0); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60,"AddTime");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum+buyNum);
				stockBean1.setStockType(0);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
			
			
			//===================================================================================================================
			//返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogList[0]->ActivityId", 0);
			returnUpdateMap.put("CatalogList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogList[0]->CatalogId", catalogsId);
			returnUpdateMap.put("CatalogList[0]->CatalogType", 0);
			returnUpdateMap.put("CatalogList[0]->PreOrderId", OrderId);
			returnUpdateMap.put("CatalogList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogList[0]->ReturnStockNum", returnNum);
			returnUpdateMap.put("CatalogList[0]->IsLiveProduct", false);
			
			returnStockListForPreOrderCall.callAndGetReturnData(returnUpdateMap);
			//Logger.verifyEquals(true, returnStockListForPreOrderCall.getReturnData().contains("ok"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",returnNum,//返还库存数量
															"activityId",0); //活动Id
															
			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
		
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals(catalogNum,new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",returnNum,//扣减库存数量
																		"ActivityId",0); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
		
	
	// 扣减库存，普通现货商品，不在活动中
	// reduceStockListForPreOrderCall / ReturnStockListForRefundBill
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_001_3() {
		Logger.start(true, "普通现货商品，不在活动中,扣减库存，返还库存");
		try {
			// Test date
			String productId = SellerProductCallService.addNewProductOnSale(sellerId, sellerName, null)
					.getJSONObject("Data").getString("ProductID");

			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);

			String catalogsId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			//int OrderId = Math.abs(TestDataManager.getRandomIntNum(8));
			int OrderId = getCurrentOrderId();
			int buyNum = -2;
			int returnNum = 2;

			// ===================================================================================================================
			// 扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> updateMap = new HashMap<String, Object>();
			updateMap.put("CatalogList[0]->CatalogId", catalogsId);
			updateMap.put("CatalogList[0]->CatalogType", 0);
			updateMap.put("CatalogList[0]->ProductId", productId);
			updateMap.put("CatalogList[0]->SellerId", sellerId);
			updateMap.put("CatalogList[0]->BuyCount", -1 * buyNum);
			updateMap.put("CatalogList[0]->BuyerId", BuyerId);
			updateMap.put("CatalogList[0]->PreOrderId", OrderId);
			updateMap.put("CatalogList[0]->IsLiveProduct", false);

			JSONObject retBean = reduceStockListForPreOrderCall.callAndGetReturnData(updateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");

			// Check SQL
			// SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals((catalogNum + buyNum), ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");

			// SQL-Ymt_ProductOrderStockLog
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper()
					.selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, // 商品Id
					"catalogId", catalogsId, // 商品规格Id
					"buyerId", BuyerId, // 买家id
					"orderId", OrderId, // 订单id
					"stockNum", buyNum, // 扣减库存数量
					"activityId", 0); // 活动Id

			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),
					"SQL-Ymt_ProductOrderStockLog ");
			// AssertService.assertTime(YMTDateUtil.getDate(),
			// (Date)ymtProductOrderStockLog.getAddTime(), 60);

			// Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()) {
				// Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum + buyNum),
						new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),
						"Mongo-ProductStockInfo 库存");

				// Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, // 商品Id
						"CatalogId", catalogsId, // 商品规格Id
						"BuyerId", BuyerId, // 买家id
						"OrderId", OrderId, // 订单id
						"StockNum", buyNum, // 扣减库存数量
						"ActivityId", 0); // 活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap, "Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date) stockOperationLogMap.get("AddTime"), 60,
						"AddTime");
			}

			if (YmtMongoDriverFactroy.isNewMongoCheck()) {
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 = catalogBean.new StockBean();
				stockBean1.setStock(catalogNum + buyNum);
				stockBean1.setStockType(0);

				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}

			// ===================================================================================================================
			// 返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogStockList[0]->RefundBillNo",  Math.abs(TestDataManager.getRandomIntNum(6)));
			returnUpdateMap.put("CatalogStockList[0]->ActivityId", 0);
			returnUpdateMap.put("CatalogStockList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogId", catalogsId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogType", 0);
			returnUpdateMap.put("CatalogStockList[0]->OrderId", OrderId);
			returnUpdateMap.put("CatalogStockList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogStockList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogStockList[0]->StockNum", returnNum);
			returnUpdateMap.put("CatalogStockList[0]->IsLiveProduct", false);

			returnStockListForRefundBillCall.callAndGetReturnData(returnUpdateMap);
			// Logger.verifyEquals(true,
			// returnStockListForPreOrderCall.getReturnData().contains("ok"),
			// "响应报文-返回码");

			// Check SQL
			// SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");

			// SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, // 商品Id
					"catalogId", catalogsId, // 商品规格Id
					"buyerId", BuyerId, // 买家id
					"orderId", OrderId, // 订单id
					"stockNum", returnNum, // 返还库存数量
					"activityId", 0); // 活动Id

			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),
					"SQL-Ymt_ProductOrderStockLog ");
			// AssertService.assertTime(YMTDateUtil.getDate(),
			// (Date)ymtProductOrderStockLog.getAddTime(), 60);

			// Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()) {
				// Mongo-ProductStockInfo
				Logger.verifyEquals(catalogNum, new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),
						"Mongo-ProductStockInfo 库存");

				// Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, // 商品Id
						"CatalogId", catalogsId, // 商品规格Id
						"BuyerId", BuyerId, // 买家id
						"OrderId", OrderId, // 订单id
						"StockNum", returnNum, // 扣减库存数量
						"ActivityId", 0); // 活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap, "Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date) stockOperationLogMap.get("AddTime"), 60);
			}

			if (YmtMongoDriverFactroy.isNewMongoCheck()) {
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 = catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);

				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
		
	//扣减库存，普通商品，在活动中
	//reduceStockListForPreOrderCall  / retutnProductStockForOrderCall
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReduceProductStockForOrder_002() {
		Logger.start(true, "普通现货商品，在活动中，扣减库存，返还库存");
		try{
			//发布商品参加活动
			String productId = SellerProductCallService.addNewProductAndApproveActivity(sellerId,
					sellerName,activityUser,activityPswd,String.valueOf(activityStartId),null);
			
			int productInActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogsId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();//共享库存
			
			YmtProductActivityStockWapper ymtActivityStockWapper = new YmtProductActivityStockWapper();
			YmtProductActivityStock ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			int activityNum = ymtActivityStock.getIstocknum();//活动库存
			
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4)); 
			//int OrderId = Math.abs(TestDataManager.getRandomIntNum(8)); 
			int OrderId = getCurrentOrderId();
			int buyNum = -3;
			int returnNum = 3;

		
			//===================================================================================================================
			//扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> reduceUpdateMap = new HashMap<String, Object>();
			reduceUpdateMap.put("CatalogList[0]->CatalogId", catalogsId);
			reduceUpdateMap.put("CatalogList[0]->CatalogType", 0);
			reduceUpdateMap.put("CatalogList[0]->ProductId", productId);
			reduceUpdateMap.put("CatalogList[0]->SellerId", sellerId);
			reduceUpdateMap.put("CatalogList[0]->BuyCount", -1*buyNum);
			reduceUpdateMap.put("CatalogList[0]->BuyerId", BuyerId);
			reduceUpdateMap.put("CatalogList[0]->PreOrderId", OrderId);
			reduceUpdateMap.put("CatalogList[0]->ActivityId", activityStartId);
			reduceUpdateMap.put("CatalogList[0]->IsLiveProduct", false);
			
			JSONObject retBean = reduceStockListForPreOrderCall.callAndGetReturnData(reduceUpdateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			Logger.verifyEquals((activityNum+buyNum), ymtActivityStock.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			
			//SQL-Ymt_ProductOrderStockLog
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper().selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",buyNum,//扣减库存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum),new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",buyNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum+buyNum),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum+buyNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
			//===================================================================================================================
			//返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogStockList[0]->ActivityId", activityStartId);
			returnUpdateMap.put("CatalogStockList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogId", catalogsId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogType", 0);
			returnUpdateMap.put("CatalogStockList[0]->OrderId", OrderId);
			returnUpdateMap.put("CatalogStockList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogStockList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogStockList[0]->StockNum", returnNum);
			returnUpdateMap.put("CatalogStockList[0]->IsLiveProduct", false);
			
			JSONObject retutnproductstockBean = JsonBeanHelper.getJsonBean(JsonBeanFile.returnproductstockforordercalltpl);
			JsonBeanHelper.updateJsonBean(retutnproductstockBean, returnUpdateMap);
			retutnProductStockForOrderCall.setData(retutnproductstockBean);
			retutnProductStockForOrderCall.callService();
			Logger.verifyEquals(true, retutnProductStockForOrderCall.getReturnData().contains("ok"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			Logger.verifyEquals(activityNum, ymtActivityStock.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			
			//SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",returnNum,//返还存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum),new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",returnNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	
	//扣减库存，普通商品，在活动中
	//reduceStockListForPreOrderCall  / returnStockListForPreOrderCall
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReduceProductStockForOrder_002_2() {
		Logger.start(true, "普通现货商品，在活动中，扣减库存，返还库存");
		try{
			//发布商品参加活动
			String productId = SellerProductCallService.addNewProductAndApproveActivity(sellerId,
					sellerName,activityUser,activityPswd,String.valueOf(activityStartId),null);
			
			int productInActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogsId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();//共享库存
			
			YmtProductActivityStockWapper ymtActivityStockWapper = new YmtProductActivityStockWapper();
			YmtProductActivityStock ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			int activityNum = ymtActivityStock.getIstocknum();//活动库存
			
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4)); 
			//int OrderId = Math.abs(TestDataManager.getRandomIntNum(8)); 
			int OrderId = getCurrentOrderId();
			int buyNum = -3;
			int returnNum = 3;

		
			//===================================================================================================================
			//扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> reduceUpdateMap = new HashMap<String, Object>();
			reduceUpdateMap.put("CatalogList[0]->CatalogId", catalogsId);
			reduceUpdateMap.put("CatalogList[0]->CatalogType", 0);
			reduceUpdateMap.put("CatalogList[0]->ProductId", productId);
			reduceUpdateMap.put("CatalogList[0]->SellerId", sellerId);
			reduceUpdateMap.put("CatalogList[0]->BuyCount", -1*buyNum);
			reduceUpdateMap.put("CatalogList[0]->BuyerId", BuyerId);
			reduceUpdateMap.put("CatalogList[0]->PreOrderId", OrderId);
			reduceUpdateMap.put("CatalogList[0]->ActivityId", activityStartId);
			reduceUpdateMap.put("CatalogList[0]->IsLiveProduct", false);
			
			JSONObject retBean = reduceStockListForPreOrderCall.callAndGetReturnData(reduceUpdateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			Logger.verifyEquals((activityNum+buyNum), ymtActivityStock.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			
			//SQL-Ymt_ProductOrderStockLog
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper().selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",buyNum,//扣减库存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum),new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",buyNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum+buyNum),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum+buyNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
			//===================================================================================================================
			//返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogList[0]->ActivityId", activityStartId);
			returnUpdateMap.put("CatalogList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogList[0]->CatalogId", catalogsId);
			returnUpdateMap.put("CatalogList[0]->CatalogType", 0);
			returnUpdateMap.put("CatalogList[0]->PreOrderId", OrderId);
			returnUpdateMap.put("CatalogList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogList[0]->ReturnStockNum", returnNum);
			returnUpdateMap.put("CatalogList[0]->IsLiveProduct", false);
			
			returnStockListForPreOrderCall.callAndGetReturnData(returnUpdateMap);
			//Logger.verifyEquals(true, returnStockListForPreOrderCall.getReturnData().contains("ok"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			Logger.verifyEquals(activityNum, ymtActivityStock.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			
			//SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",returnNum,//返还存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum),new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",returnNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
	//扣减库存，普通商品，在活动中
	// reduceStockListForPreOrderCall / retutnProductStockForOrderCall
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceProductStockForOrder_002_3() {
		Logger.start(true, "普通现货商品，在活动中，扣减库存，返还库存");
		try {
			// 发布商品参加活动
			String productId = SellerProductCallService.addNewProductAndApproveActivity(sellerId, sellerName,
					activityUser, activityPswd, String.valueOf(activityStartId), null);

			int productInActivityId = new YmtProductsInActivityWapper().selectByProductId(productId)
					.getIproductinactivityid();

			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogsId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();// 共享库存

			YmtProductActivityStockWapper ymtActivityStockWapper = new YmtProductActivityStockWapper();
			YmtProductActivityStock ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			int activityNum = ymtActivityStock.getIstocknum();// 活动库存

			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			// int OrderId = Math.abs(TestDataManager.getRandomIntNum(8));
			int OrderId = getCurrentOrderId();
			int buyNum = -3;
			int returnNum = 3;

			// ===================================================================================================================
			// 扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> reduceUpdateMap = new HashMap<String, Object>();
			reduceUpdateMap.put("CatalogList[0]->CatalogId", catalogsId);
			reduceUpdateMap.put("CatalogList[0]->CatalogType", 0);
			reduceUpdateMap.put("CatalogList[0]->ProductId", productId);
			reduceUpdateMap.put("CatalogList[0]->SellerId", sellerId);
			reduceUpdateMap.put("CatalogList[0]->BuyCount", -1 * buyNum);
			reduceUpdateMap.put("CatalogList[0]->BuyerId", BuyerId);
			reduceUpdateMap.put("CatalogList[0]->PreOrderId", OrderId);
			reduceUpdateMap.put("CatalogList[0]->ActivityId", activityStartId);
			reduceUpdateMap.put("CatalogList[0]->IsLiveProduct", false);

			JSONObject retBean = reduceStockListForPreOrderCall.callAndGetReturnData(reduceUpdateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");

			// Check SQL
			// SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");

			// SQL-Ymt_ProductActivityStock
			ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			Logger.verifyEquals((activityNum + buyNum), ymtActivityStock.getIstocknum(),
					"SQL-Ymt_ProductActivityStock 商品库存数量");

			// SQL-Ymt_ProductOrderStockLog
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper()
					.selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, // 商品Id
					"catalogId", catalogsId, // 商品规格Id
					"buyerId", BuyerId, // 买家id
					"orderId", OrderId, // 订单id
					"stockNum", buyNum, // 扣减库存数量
					"activityId", activityStartId); // 活动Id

			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),
					"SQL-Ymt_ProductOrderStockLog ");
			// AssertService.assertTime(YMTDateUtil.getDate(),
			// (Date)ymtProductOrderStockLog.getAddTime(), 60);

			// Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()) {
				// Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum),
						new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),
						"Mongo-ProductStockInfo 库存");

				// Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, // 商品Id
						"CatalogId", catalogsId, // 商品规格Id
						"BuyerId", BuyerId, // 买家id
						"OrderId", OrderId, // 订单id
						"StockNum", buyNum, // 扣减库存数量
						"ActivityId", activityStartId); // 活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap, "Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date) stockOperationLogMap.get("AddTime"), 60);

				// Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper()
						.getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, // 商品Id
						"CatalogId", catalogsId, // 商品规格Id
						"ProductActivityId", productInActivityId, // 商品活动Id
						"ActivityStockNum", (activityNum + buyNum), // 活动库存
						"ActivityId", activityStartId); // 活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,
						"Mongo-ProductActivityStockInfo ");
			}

			if (YmtMongoDriverFactroy.isNewMongoCheck()) {
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 = catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);

				CatalogBean.StockBean stockBean2 = catalogBean.new StockBean();
				stockBean2.setStock(activityNum + buyNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);

				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1, stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}

			// ===================================================================================================================
			// 返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogStockList[0]->RefundBillNo",  Math.abs(TestDataManager.getRandomIntNum(6)));
			returnUpdateMap.put("CatalogStockList[0]->ActivityId", activityStartId);
			returnUpdateMap.put("CatalogStockList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogId", catalogsId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogType", 0);
			returnUpdateMap.put("CatalogStockList[0]->OrderId", OrderId);
			returnUpdateMap.put("CatalogStockList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogStockList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogStockList[0]->StockNum", returnNum);
			returnUpdateMap.put("CatalogStockList[0]->IsLiveProduct", false);
			
			
			returnStockListForRefundBillCall.callAndGetReturnData(returnUpdateMap);
			Logger.verifyEquals(true, returnStockListForRefundBillCall.getReturnData().contains("ok"), "响应报文-返回码");

			// Check SQL
			// SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");

			// SQL-Ymt_ProductActivityStock
			ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			Logger.verifyEquals(activityNum, ymtActivityStock.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");

			// SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, // 商品Id
					"catalogId", catalogsId, // 商品规格Id
					"buyerId", BuyerId, // 买家id
					"orderId", OrderId, // 订单id
					"stockNum", returnNum, // 返还存数量
					"activityId", activityStartId); // 活动Id

			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),
					"SQL-Ymt_ProductOrderStockLog ");
			// AssertService.assertTime(YMTDateUtil.getDate(),
			// (Date)ymtProductOrderStockLog.getAddTime(), 60);

			// Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()) {
				// Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum),
						new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),
						"Mongo-ProductStockInfo 库存");

				// Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, // 商品Id
						"CatalogId", catalogsId, // 商品规格Id
						"BuyerId", BuyerId, // 买家id
						"OrderId", OrderId, // 订单id
						"StockNum", returnNum, // 扣减库存数量
						"ActivityId", activityStartId); // 活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap, "Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date) stockOperationLogMap.get("AddTime"), 60);

				// Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper()
						.getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, // 商品Id
						"CatalogId", catalogsId, // 商品规格Id
						"ProductActivityId", productInActivityId, // 商品活动Id
						"ActivityStockNum", (activityNum), // 活动库存
						"ActivityId", activityStartId); // 活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,
						"Mongo-ProductActivityStockInfo ");
			}

			if (YmtMongoDriverFactroy.isNewMongoCheck()) {
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 = catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);

				CatalogBean.StockBean stockBean2 = catalogBean.new StockBean();
				stockBean2.setStock(activityNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);

				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1, stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
		
/*	//扣减库存，FBX商品，不在活动中
	@Test
	@Ignore
	@Category({P1.class})
	@TestCase
	public void Tc_ReduceProductStockForOrder_003() {
		Logger.start(true, "扣减库存，FBX商品，不在活动中");
		try{
			//Test date
			String productId = new AddFbxProductCall().callAndGetReturnData(MapUtil.hashMap("UserID", sellerId, "LoginID", sellerName)).getJSONObject("Data").getString("ProductID");
		
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			
			String catalogsId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			String sSku = ymtCatalog.getsSKU();
			
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4)); 
			int OrderId = Math.abs(TestDataManager.getRandomIntNum(8)); 
			int buyNum = -2;
			int returnNum = 2;
			
			//===================================================================================================================
			//扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> reduceUpdateMap = new HashMap<String, Object>();
			reduceUpdateMap.put("CatalogList[0]->CatalogId", catalogsId);
			reduceUpdateMap.put("CatalogList[0]->CatalogType", 2);// 备货方式（0-现货，1-代购，2-FBX）
			reduceUpdateMap.put("CatalogList[0]->ProductId", productId);
			reduceUpdateMap.put("CatalogList[0]->SellerId", sellerId);
			reduceUpdateMap.put("CatalogList[0]->BuyCount", buyNum);
			reduceUpdateMap.put("CatalogList[0]->BuyerId", BuyerId);
			reduceUpdateMap.put("CatalogList[0]->OrderId", OrderId);
			
			JSONObject retBean = reduceProductStockForOrderCall.callAndGetReturnData(reduceUpdateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals((catalogNum+buyNum), ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductOrderStockLog
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper().selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",buyNum,//扣减库存数量
															"activityId",0); //活动Id
															
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
		
			//SQL-Ymt_StockChangeDetail
			//YmtStockChangeDetail ymtStockChangeDetail = new YmtStockChangeDetailWapper().selectByCatalogId(catalogsId).get(0);
			Map<String, Object> tgtsqlMap2 = MapUtil.hashMap("sSKU",sSku, //商品规格Id
																"iStock",Math.abs(buyNum),//扣减库存数量
																"sCatalogId",catalogsId); //规格Id
			
			
			
			//AssertService.assertResultEqual(tgtsqlMap2, MapUtil.pojoToMap(ymtStockChangeDetail),"SQL-Ymt_StockChangeDetail ");
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum+buyNum),new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",buyNum,//扣减库存数量
																		"ActivityId",0); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum+buyNum);
				stockBean1.setStockType(0);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
			//===================================================================================================================
			//返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogStockList[0]->ActivityId", 0);
			returnUpdateMap.put("CatalogStockList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogId", catalogsId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogType", 2);
			returnUpdateMap.put("CatalogStockList[0]->OrderId", OrderId);
			returnUpdateMap.put("CatalogStockList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogStockList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogStockList[0]->StockNum", returnNum);
			
			JSONObject retutnproductstockBean = JsonBeanHelper.getJsonBean(JsonBeanFile.returnproductstockforordercalltpl);
			JsonBeanHelper.updateJsonBean(retutnproductstockBean, returnUpdateMap);
			retutnProductStockForOrderCall.setData(retutnproductstockBean);
			retutnProductStockForOrderCall.callService();
			Logger.verifyEquals(true, retutnProductStockForOrderCall.getReturnData().contains("ok"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",returnNum,//返还库存数量
															"activityId",0); //活动Id
															
			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
		//	AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
		
			//SQL-Ymt_StockChangeDetail
			ymtStockChangeDetail = new YmtStockChangeDetailWapper().selectByCatalogId(catalogsId).get(0);
			Map<String, Object> tgtsqlMap3 = MapUtil.hashMap("sSKU",sSku, //商品规格Id
																"iStock",0,//扣减库存数量
																"sCatalogId",catalogsId); //规格Id
			
			AssertService.assertResultEqual(tgtsqlMap3, MapUtil.pojoToMap(ymtStockChangeDetail),"SQL-Ymt_StockChangeDetail ");
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals(catalogNum,new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",returnNum,//扣减库存数量
																		"ActivityId",0); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
		
	
	
	//扣减库存，FBX商品，在活动中
	@Test
	@Ignore
	@Category({P1.class})
	@TestCase
	public void Tc_ReduceProductStockForOrder_005() {
		Logger.start(true, "扣减库存，FBX商品，在活动中");
		try{
			//发布商品参加活动
			String productId = SellerProductCallService.addNewProductAndApproveActivity(sellerId,
					sellerName,activityUser,activityPswd,String.valueOf(activityStartId),null);
			
			//修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId, 2);
			
			int productInActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogsId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();//共享库存
			
			YmtProductActivityStockWapper ymtActivityStockWapper = new YmtProductActivityStockWapper();
			YmtProductActivityStock ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			int activityNum = ymtActivityStock.getIstocknum();//活动库存
			
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4)); 
			//int OrderId = Math.abs(TestDataManager.getRandomIntNum(8)); 
			int OrderId = getCurrentOrderId(); //返活动库存 需检查订单时间
			int buyNum = -3;
			int returnNum = 3;

			//===================================================================================================================
			//扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> reductUpdateMap = new HashMap<String, Object>();
			reductUpdateMap.put("CatalogList[0]->CatalogId", catalogsId);
			reductUpdateMap.put("CatalogList[0]->CatalogType", 0);
			reductUpdateMap.put("CatalogList[0]->ProductId", productId);
			reductUpdateMap.put("CatalogList[0]->SellerId", sellerId);
			reductUpdateMap.put("CatalogList[0]->BuyCount", buyNum);
			reductUpdateMap.put("CatalogList[0]->BuyerId", BuyerId);
			reductUpdateMap.put("CatalogList[0]->OrderId", OrderId);
			reductUpdateMap.put("CatalogList[0]->ActivityId", activityStartId);
			
			JSONObject retBean = reduceProductStockForOrderCall.callAndGetReturnData(reductUpdateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			Logger.verifyEquals((activityNum+buyNum), ymtActivityStock.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			
			//SQL-Ymt_ProductOrderStockLog
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper().selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",buyNum,//扣减库存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
		//	AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum),new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",buyNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum+buyNum),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum+buyNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
			//===================================================================================================================
			//返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogStockList[0]->ActivityId", activityStartId);
			returnUpdateMap.put("CatalogStockList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogId", catalogsId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogType", 2);
			returnUpdateMap.put("CatalogStockList[0]->OrderId", OrderId);
			returnUpdateMap.put("CatalogStockList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogStockList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogStockList[0]->StockNum", returnNum);
			
			JSONObject retutnproductstockBean = JsonBeanHelper.getJsonBean(JsonBeanFile.returnproductstockforordercalltpl);
			JsonBeanHelper.updateJsonBean(retutnproductstockBean, returnUpdateMap);
			retutnProductStockForOrderCall.setData(retutnproductstockBean);
			retutnProductStockForOrderCall.callService();
			Logger.verifyEquals(true, retutnProductStockForOrderCall.getReturnData().contains("ok"), "响应报文-返回码");
			
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			Logger.verifyEquals(catalogNum, ymtCatalog.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock = ymtActivityStockWapper.selectByProductId(productId).get(0);
			Logger.verifyEquals(activityNum, ymtActivityStock.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			
			//SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",returnNum,//返还存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum),new ProductStockInfoWapper().getByCatalogId(catalogsId).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",returnNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
			}
			
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean));
			}
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	//多规格 扣减库存，普通现货商品，不在活动中
	@Test
	@Ignore
	@Category({P1.class})
	@TestCase
	public void Tc_ReduceProductStockForOrder_006() {
		Logger.start(true, "多库存， 普通现货商品，不在活动中,扣减库存，返还库存");
		try{
			//Test date
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc1.json");
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID",sellerId,"LoginID",sellerName));
			String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
		
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			
			String catalogsId1 = ymtCatalog1.getsCatalogId();
			int catalogNum1 = ymtCatalog1.getiNum();
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4)); 
			int OrderId = Math.abs(TestDataManager.getRandomIntNum(8)); 
			int buyNum = -2;
			int returnNum = 2;
			
			YmtCatalogsI ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1);
			String catalogsId2 = ymtCatalog2.getsCatalogId();
			int catalogNum2= ymtCatalog2.getiNum();
			
			
			
		
			//===================================================================================================================
			//扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> updateMap = new HashMap<String, Object>();
			updateMap.put("CatalogList[0]->CatalogId", catalogsId1);
			updateMap.put("CatalogList[0]->CatalogType", 0);
			updateMap.put("CatalogList[0]->ProductId", productId);
			updateMap.put("CatalogList[0]->SellerId", sellerId);
			updateMap.put("CatalogList[0]->BuyCount", buyNum);
			updateMap.put("CatalogList[0]->BuyerId", BuyerId);
			updateMap.put("CatalogList[0]->OrderId", OrderId);
			
			JSONObject retBean = reduceProductStockForOrderCall.callAndGetReturnData(updateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId1);
			Logger.verifyEquals((catalogNum1+buyNum), ymtCatalog1.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId2);
			Logger.verifyEquals(catalogNum2, ymtCatalog2.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductOrderStockLog 
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper().selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId1, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",buyNum,//扣减库存数量
															"activityId",0); //活动Id
															
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
		
			
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals((catalogNum1+buyNum),new ProductStockInfoWapper().getByCatalogId(catalogsId1).get("StockNum"),"Mongo-ProductStockInfo 库存");
				Logger.verifyEquals(catalogNum2,new ProductStockInfoWapper().getByCatalogId(catalogsId2).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",buyNum,//扣减库存数量
																		"ActivityId",0); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum1+buyNum);
				stockBean1.setStockType(0);
				catalogBean.setCatalogId(catalogsId1);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				
				CatalogBean catalogBean2 = new CatalogBean();
				CatalogBean.StockBean stockBean2 =catalogBean2.new StockBean();
				stockBean2.setStock(catalogNum2);
				stockBean2.setStockType(0);
				catalogBean2.setCatalogId(catalogsId2);
				catalogBean2.setStockBean(Arrays.asList(stockBean2));
				
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean,catalogBean2));
			}
			
			
			
			
			//===================================================================================================================
			//返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogStockList[0]->ActivityId", 0);
			returnUpdateMap.put("CatalogStockList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogId", catalogsId1);
			returnUpdateMap.put("CatalogStockList[0]->CatalogType", 0);
			returnUpdateMap.put("CatalogStockList[0]->OrderId", OrderId);
			returnUpdateMap.put("CatalogStockList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogStockList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogStockList[0]->StockNum", returnNum);
			
			JSONObject retutnproductstockBean = JsonBeanHelper.getJsonBean(JsonBeanFile.returnproductstockforordercalltpl);
			JsonBeanHelper.updateJsonBean(retutnproductstockBean, returnUpdateMap);
			retutnProductStockForOrderCall.setData(retutnproductstockBean);
			retutnProductStockForOrderCall.callService();
			Logger.verifyEquals(true, retutnProductStockForOrderCall.getReturnData().contains("ok"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId1);
			Logger.verifyEquals(catalogNum1, ymtCatalog1.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId2);
			Logger.verifyEquals(catalogNum2, ymtCatalog2.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId1, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",returnNum,//返还库存数量
															"activityId",0); //活动Id
															
			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
		
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals(catalogNum1,new ProductStockInfoWapper().getByCatalogId(catalogsId1).get("StockNum"),"Mongo-ProductStockInfo 库存");
				Logger.verifyEquals(catalogNum2,new ProductStockInfoWapper().getByCatalogId(catalogsId2).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",returnNum,//扣减库存数量
																		"ActivityId",0); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum1);
				stockBean1.setStockType(0);
				catalogBean.setCatalogId(catalogsId1);
				catalogBean.setStockBean(Arrays.asList(stockBean1));
				
				CatalogBean catalogBean2 = new CatalogBean();
				CatalogBean.StockBean stockBean2 =catalogBean2.new StockBean();
				stockBean2.setStock(catalogNum2);
				stockBean2.setStockType(0);
				catalogBean2.setCatalogId(catalogsId2);
				catalogBean2.setStockBean(Arrays.asList(stockBean2));
				
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean,catalogBean2));
			}
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	//多规格 扣减库存 普通商品 在活动中
	@Test
	@Ignore
	@Category({P1.class})
	@TestCase
	public void Tc_ReduceProductStockForOrder_007() {
		Logger.start(true, "多规格,普通现货商品，在活动中，扣减库存，返还库存");
		try{
			String sellerName = "wesper";
			 int sellerId = 3383;
			
			JSONObject liveResponseBean = LiveCallService.createLiveInProgress(sellerName, Integer.valueOf(sellerId));
			int liveId =  liveResponseBean.getJSONObject("Data").getInt("ActivityId");
			
			//发布商品参加活动
			for(int i=0;i<10;i++){
				JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc1.json");
				JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID",sellerId,"LoginID",sellerName));
				String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
				System.out.println(productId);
				SellerProductCallService.addProductInLive(Integer.valueOf(sellerId), liveId, productId);
				SellerProductCallService.approveActivity( sellerId, activityUser, activityPswd, String.valueOf(activityStartId), productId);
			}
			
			int productInActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogsId1 = ymtCatalog1.getsCatalogId();
			int catalogNum1 = ymtCatalog1.getiNum();//共享库存
			
			YmtCatalogsI ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1);
			String catalogsId2 = ymtCatalog2.getsCatalogId();
			int catalogNum2 = ymtCatalog2.getiNum();//共享库存
			
			
			YmtProductActivityStockWapper ymtActivityStockWapper = new YmtProductActivityStockWapper();
			YmtProductActivityStock ymtActivityStock1 = ymtActivityStockWapper.selectByCatalogId(catalogsId1);
			int activityNum1 = ymtActivityStock1.getIstocknum();//活动库存
			
			YmtProductActivityStock ymtActivityStock2 = ymtActivityStockWapper.selectByCatalogId(catalogsId2);
			int activityNum2 = ymtActivityStock1.getIstocknum();//活动库存
			
			
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4)); 
			//int OrderId = Math.abs(TestDataManager.getRandomIntNum(8)); 
			int OrderId = getCurrentOrderId();
			int buyNum = -3;
			int returnNum = 3;

		
			//===================================================================================================================
			//扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> reduceUpdateMap = new HashMap<String, Object>();
			reduceUpdateMap.put("CatalogList[0]->CatalogId", catalogsId1);
			reduceUpdateMap.put("CatalogList[0]->CatalogType", 0);
			reduceUpdateMap.put("CatalogList[0]->ProductId", productId);
			reduceUpdateMap.put("CatalogList[0]->SellerId", sellerId);
			reduceUpdateMap.put("CatalogList[0]->BuyCount", buyNum);
			reduceUpdateMap.put("CatalogList[0]->BuyerId", BuyerId);
			reduceUpdateMap.put("CatalogList[0]->OrderId", OrderId);
			reduceUpdateMap.put("CatalogList[0]->ActivityId", activityStartId);
			
			JSONObject retBean = reduceProductStockForOrderCall.callAndGetReturnData(reduceUpdateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId1);
			Logger.verifyEquals(catalogNum1, ymtCatalog1.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock1 = ymtActivityStockWapper.selectByCatalogId(catalogsId1);
			Logger.verifyEquals((activityNum1+buyNum), ymtActivityStock1.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			//SQL-Ymt_Catalogs
			ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId2);
			Logger.verifyEquals(catalogNum2, ymtCatalog2.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock2 = ymtActivityStockWapper.selectByCatalogId(catalogsId2);
			Logger.verifyEquals((activityNum2), ymtActivityStock2.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			
			
			
			//SQL-Ymt_ProductOrderStockLog
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper().selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId1, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",buyNum,//扣减库存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals(catalogNum1,new ProductStockInfoWapper().getByCatalogId(catalogsId1).get("StockNum"),"Mongo-ProductStockInfo 库存");
				Logger.verifyEquals(catalogNum2,new ProductStockInfoWapper().getByCatalogId(catalogsId2).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",buyNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByCatalogIdId(catalogsId1);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum1+buyNum),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap2 = new ProductActivityStockInfoWapper().getByCatalogIdId(catalogsId2);
				Map<String, Object> tgtOldMongolMap3 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId2, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum2),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap3, productActivityStockInfoMap2,"Mongo-ProductActivityStockInfo ");
				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum1);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum1+buyNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId1);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				
				CatalogBean catalogBean2 = new CatalogBean();
				CatalogBean.StockBean stockBean3 =catalogBean2.new StockBean();
				stockBean3.setStock(catalogNum2);
				stockBean3.setStockType(0);
				
				CatalogBean.StockBean stockBean4 =catalogBean2.new StockBean();
				stockBean4.setStock(activityNum2);
				stockBean4.setProductInActivityId(productInActivityId);
				stockBean4.setStockType(1);
				
				catalogBean2.setCatalogId(catalogsId2);
				catalogBean2.setStockBean(Arrays.asList(stockBean3,stockBean4));
				
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean,catalogBean2));
			}
			
			
			//===================================================================================================================
			//返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogStockList[0]->ActivityId", activityStartId);
			returnUpdateMap.put("CatalogStockList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogId", catalogsId1);
			returnUpdateMap.put("CatalogStockList[0]->CatalogType", 0);
			returnUpdateMap.put("CatalogStockList[0]->OrderId", OrderId);
			returnUpdateMap.put("CatalogStockList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogStockList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogStockList[0]->StockNum", returnNum);
			
			JSONObject retutnproductstockBean = JsonBeanHelper.getJsonBean(JsonBeanFile.returnproductstockforordercalltpl);
			JsonBeanHelper.updateJsonBean(retutnproductstockBean, returnUpdateMap);
			retutnProductStockForOrderCall.setData(retutnproductstockBean);
			retutnProductStockForOrderCall.callService();
			Logger.verifyEquals(true, retutnProductStockForOrderCall.getReturnData().contains("ok"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId1);
			Logger.verifyEquals(catalogNum1, ymtCatalog1.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId2);
			Logger.verifyEquals(catalogNum2, ymtCatalog2.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock1 = ymtActivityStockWapper.selectByCatalogId(catalogsId1);
			Logger.verifyEquals(activityNum1, ymtActivityStock1.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			ymtActivityStock2 = ymtActivityStockWapper.selectByCatalogId(catalogsId2);
			Logger.verifyEquals(activityNum2, ymtActivityStock2.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			//SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId1, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",returnNum,//返还存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals(catalogNum1,new ProductStockInfoWapper().getByCatalogId(catalogsId1).get("StockNum"),"Mongo-ProductStockInfo 库存");
				Logger.verifyEquals(catalogNum2,new ProductStockInfoWapper().getByCatalogId(catalogsId2).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",returnNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByCatalogIdId(catalogsId1);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum1),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
				
				
				Map<String, Object> productActivityStockInfoMap2 = new ProductActivityStockInfoWapper().getByCatalogIdId(catalogsId2);
				Map<String, Object> tgtOldMongolMap3 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId2, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum2),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap3, productActivityStockInfoMap2,"Mongo-ProductActivityStockInfo ");
			}
			
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum1);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum1);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId1);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				
				CatalogBean catalogBean2 = new CatalogBean();
				CatalogBean.StockBean stockBean3 =catalogBean2.new StockBean();
				stockBean3.setStock(catalogNum2);
				stockBean3.setStockType(0);
				
				CatalogBean.StockBean stockBean4 =catalogBean2.new StockBean();
				stockBean4.setStock(activityNum2);
				stockBean4.setProductInActivityId(productInActivityId);
				stockBean4.setStockType(1);
				
				catalogBean2.setCatalogId(catalogsId2);
				catalogBean2.setStockBean(Arrays.asList(stockBean3,stockBean4));
				
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean,catalogBean2));
			}
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	//多规格 参加活动，解除活动，又参加活动，扣库存，返库存
	@Test
	@Category({P1.class})
	@Ignore
	@TestCase
	public void Tc_ReduceProductStockForOrder_008() {
		Logger.start(true, "多规格 参加活动，解除活动，又参加活动，扣库存，返库存");
		try{
			//发布商品参加活动
			JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc1.json");
			JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID",sellerId,"LoginID",sellerName));
			String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");
			
			Thread.sleep(5000);
			
			
			
			//参加活动1
			SellerProductCallService.approveActivity( sellerId, activityUser, activityPswd, String.valueOf(activityStartId), productId);
			int productInActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();
			
			//参加活动2
			ActivityCallService.applyProductInActivity(sellerId, productId, String.valueOf(20116), new HashMap<String,Object>());
			int productInActivityId2 = new YmtProductsInActivityWapper().selectByProductIdAndActivityId(productId, 20116).getIproductinactivityid();
			Map<String, Object> mapS = MapUtil.hashMap("productBeginTime", "2024-10-21 23:34:32", "productEndTime", "2024-10-30 23:34:32");
			AdminCallService.approveProductInActivity(activityUser,activityPswd,String.valueOf(productInActivityId2),mapS);	
			
			
			
			//结束活动
			AdminCallService.closeProductInActivity(activityUser, activityPswd, String.valueOf(productInActivityId));
				
			Thread.sleep(10000);
			//参加活动
			SellerProductCallService.approveActivity( sellerId, activityUser, activityPswd, String.valueOf(activityStartId), productId);
			productInActivityId = new YmtProductsInActivityWapper().selectByProductId(productId).getIproductinactivityid();

			
			
			
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogsId1 = ymtCatalog1.getsCatalogId();
			int catalogNum1 = ymtCatalog1.getiNum();//共享库存
			
			YmtCatalogsI ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(1);
			String catalogsId2 = ymtCatalog2.getsCatalogId();
			int catalogNum2 = ymtCatalog2.getiNum();//共享库存
			
			
			YmtProductActivityStockWapper ymtActivityStockWapper = new YmtProductActivityStockWapper();
			YmtProductActivityStock ymtActivityStock1 = ymtActivityStockWapper.selectByCatalogId(catalogsId1);
			int activityNum1 = ymtActivityStock1.getIstocknum();//活动库存
			
			YmtProductActivityStock ymtActivityStock2 = ymtActivityStockWapper.selectByCatalogId(catalogsId2);
			int activityNum2 = ymtActivityStock1.getIstocknum();//活动库存
			
			
			int BuyerId = Math.abs(TestDataManager.getRandomIntNum(4)); 
			//int OrderId = Math.abs(TestDataManager.getRandomIntNum(8)); 
			int OrderId = getCurrentOrderId();
			int buyNum = -3;
			int returnNum = 3;

		
			//===================================================================================================================
			//扣减库存
			Logger.comment("扣减库存");
			Map<String, Object> reduceUpdateMap = new HashMap<String, Object>();
			reduceUpdateMap.put("CatalogList[0]->CatalogId", catalogsId1);
			reduceUpdateMap.put("CatalogList[0]->CatalogType", 0);
			reduceUpdateMap.put("CatalogList[0]->ProductId", productId);
			reduceUpdateMap.put("CatalogList[0]->SellerId", sellerId);
			reduceUpdateMap.put("CatalogList[0]->BuyCount", buyNum);
			reduceUpdateMap.put("CatalogList[0]->BuyerId", BuyerId);
			reduceUpdateMap.put("CatalogList[0]->OrderId", OrderId);
			reduceUpdateMap.put("CatalogList[0]->ActivityId", activityStartId);
			
			JSONObject retBean = reduceProductStockForOrderCall.callAndGetReturnData(reduceUpdateMap);
			Logger.verifyEquals(200, retBean.getInt("Code"), "响应报文-返回码");
			
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId1);
			Logger.verifyEquals(catalogNum1, ymtCatalog1.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock1 = ymtActivityStockWapper.selectByCatalogId(catalogsId1);
			Logger.verifyEquals((activityNum1+buyNum), ymtActivityStock1.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			//SQL-Ymt_Catalogs
			ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId2);
			Logger.verifyEquals(catalogNum2, ymtCatalog2.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock2 = ymtActivityStockWapper.selectByCatalogId(catalogsId2);
			Logger.verifyEquals((activityNum2), ymtActivityStock2.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			
			
			
			//SQL-Ymt_ProductOrderStockLog
			YmtProductOrderStockLog ymtProductOrderStockLog = new YmtProductOrderStockLogWapper().selectByProductId(productId).get(0);
			Map<String, Object> tgtsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId1, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",buyNum,//扣减库存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals(catalogNum1,new ProductStockInfoWapper().getByCatalogId(catalogsId1).get("StockNum"),"Mongo-ProductStockInfo 库存");
				Logger.verifyEquals(catalogNum2,new ProductStockInfoWapper().getByCatalogId(catalogsId2).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = new StockOperationLogWapper().getByProductId(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",buyNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByCatalogIdId(catalogsId1);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum1+buyNum),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap2 = new ProductActivityStockInfoWapper().getByCatalogIdId(catalogsId2);
				Map<String, Object> tgtOldMongolMap3 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId2, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum2),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap3, productActivityStockInfoMap2,"Mongo-ProductActivityStockInfo ");
				
			}
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum1);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum1+buyNum);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId1);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				
				CatalogBean catalogBean2 = new CatalogBean();
				CatalogBean.StockBean stockBean3 =catalogBean2.new StockBean();
				stockBean3.setStock(catalogNum2);
				stockBean3.setStockType(0);
				
				CatalogBean.StockBean stockBean4 =catalogBean2.new StockBean();
				stockBean4.setStock(activityNum2);
				stockBean4.setProductInActivityId(productInActivityId);
				stockBean4.setStockType(1);
				
				catalogBean2.setCatalogId(catalogsId2);
				catalogBean2.setStockBean(Arrays.asList(stockBean3,stockBean4));
				
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean,catalogBean2));
			}
			
			
			//===================================================================================================================
			//返还库存
			Logger.comment("返还库存");
			Map<String, Object> returnUpdateMap = new HashMap<String, Object>();
			returnUpdateMap.put("CatalogStockList[0]->ActivityId", activityStartId);
			returnUpdateMap.put("CatalogStockList[0]->BuyerId", BuyerId);
			returnUpdateMap.put("CatalogStockList[0]->CatalogId", catalogsId1);
			returnUpdateMap.put("CatalogStockList[0]->CatalogType", 0);
			returnUpdateMap.put("CatalogStockList[0]->OrderId", OrderId);
			returnUpdateMap.put("CatalogStockList[0]->ProductId", productId);
			returnUpdateMap.put("CatalogStockList[0]->SellerId", sellerId);
			returnUpdateMap.put("CatalogStockList[0]->StockNum", returnNum);
			
			JSONObject retutnproductstockBean = JsonBeanHelper.getJsonBean(JsonBeanFile.returnproductstockforordercalltpl);
			JsonBeanHelper.updateJsonBean(retutnproductstockBean, returnUpdateMap);
			retutnProductStockForOrderCall.setData(retutnproductstockBean);
			retutnProductStockForOrderCall.callService();
			Logger.verifyEquals(true, retutnProductStockForOrderCall.getReturnData().contains("ok"), "响应报文-返回码");
			
			//Check SQL
			//SQL-Ymt_Catalogs
			ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId1);
			Logger.verifyEquals(catalogNum1, ymtCatalog1.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogsId2);
			Logger.verifyEquals(catalogNum2, ymtCatalog2.getiNum(), "SQL-Ymt_Catalogs 商品库存数量");
			
			
			//SQL-Ymt_ProductActivityStock
			ymtActivityStock1 = ymtActivityStockWapper.selectByCatalogId(catalogsId1);
			Logger.verifyEquals(activityNum1, ymtActivityStock1.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			ymtActivityStock2 = ymtActivityStockWapper.selectByCatalogId(catalogsId2);
			Logger.verifyEquals(activityNum2, ymtActivityStock2.getIstocknum(), "SQL-Ymt_ProductActivityStock 商品库存数量");
			
			
			//SQL-Ymt_ProductOrderStockLog
			ymtProductOrderStockLog = getReturnProductOrderStockLog(productId);
			Map<String, Object> tgtReturnsqlMap = MapUtil.hashMap("productId", productId, //商品Id
															"catalogId",catalogsId1, //商品规格Id
															"buyerId", BuyerId, //买家id
															"orderId",OrderId,  //订单id
															"stockNum",returnNum,//返还存数量
															"activityId",activityStartId); //活动Id
															
			AssertService.assertResultEqual(tgtReturnsqlMap, MapUtil.pojoToMap(ymtProductOrderStockLog),"SQL-Ymt_ProductOrderStockLog ");
			//AssertService.assertTime(YMTDateUtil.getDate(), (Date)ymtProductOrderStockLog.getAddTime(), 60);
			
			
			
			//Check Mongo
			if (YmtMongoDriverFactroy.isOldMongoCheck()){
				//Mongo-ProductStockInfo
				Logger.verifyEquals(catalogNum1,new ProductStockInfoWapper().getByCatalogId(catalogsId1).get("StockNum"),"Mongo-ProductStockInfo 库存");
				Logger.verifyEquals(catalogNum2,new ProductStockInfoWapper().getByCatalogId(catalogsId2).get("StockNum"),"Mongo-ProductStockInfo 库存");
				
				//Mongo-StockOperationLog
				Map<String, Object> stockOperationLogMap = getReturnStockOperationLogMap(productId);
				Map<String, Object> tgtOldMongolMap = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"BuyerId", BuyerId, //买家id
																		"OrderId",OrderId,  //订单id
																		"StockNum",returnNum,//扣减库存数量
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap, stockOperationLogMap,"Mongo-StockOperationLog ");
				AssertService.assertTime(YMTDateUtil.getDate(), (Date)stockOperationLogMap.get("AddTime"), 60);
				
				//Mongo-ProductActivityStockInfo
				Map<String, Object> productActivityStockInfoMap = new ProductActivityStockInfoWapper().getByCatalogIdId(catalogsId1);
				Map<String, Object> tgtOldMongolMap2 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId1, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum1),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap2, productActivityStockInfoMap,"Mongo-ProductActivityStockInfo ");
				
				
				Map<String, Object> productActivityStockInfoMap2 = new ProductActivityStockInfoWapper().getByCatalogIdId(catalogsId2);
				Map<String, Object> tgtOldMongolMap3 = MapUtil.hashMap("ProductId", productId, //商品Id
																		"CatalogId",catalogsId2, //商品规格Id
																		"ProductActivityId",productInActivityId, //商品活动Id
																		"ActivityStockNum",(activityNum2),//活动库存
																		"ActivityId",activityStartId); //活动Id
				AssertService.assertResultEqual(tgtOldMongolMap3, productActivityStockInfoMap2,"Mongo-ProductActivityStockInfo ");
			}
			
			
			if (YmtMongoDriverFactroy.isNewMongoCheck()){
				CatalogBean catalogBean = new CatalogBean();
				CatalogBean.StockBean stockBean1 =catalogBean.new StockBean();
				stockBean1.setStock(catalogNum1);
				stockBean1.setStockType(0);
				
				CatalogBean.StockBean stockBean2 =catalogBean.new StockBean();
				stockBean2.setStock(activityNum1);
				stockBean2.setProductInActivityId(productInActivityId);
				stockBean2.setStockType(1);
				
				catalogBean.setCatalogId(catalogsId1);
				catalogBean.setStockBean(Arrays.asList(stockBean1,stockBean2));
				
				CatalogBean catalogBean2 = new CatalogBean();
				CatalogBean.StockBean stockBean3 =catalogBean2.new StockBean();
				stockBean3.setStock(catalogNum2);
				stockBean3.setStockType(0);
				
				CatalogBean.StockBean stockBean4 =catalogBean2.new StockBean();
				stockBean4.setStock(activityNum2);
				stockBean4.setProductInActivityId(productInActivityId);
				stockBean4.setStockType(1);
				
				catalogBean2.setCatalogId(catalogsId2);
				catalogBean2.setStockBean(Arrays.asList(stockBean3,stockBean4));
				
				ProductStockCallService.checkNewMongoCatalogStock(productId, Arrays.asList(catalogBean,catalogBean2));
			}
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	*/
	
	
	
	//获取当前日期订单号
	private static int getCurrentOrderId() throws InterruptedException{
		YmtOrdersWapper ymtOrdersWapper = new YmtOrdersWapper();
		int iOrder = ymtOrdersWapper.selectEarlyOrderInfo().getIorderid();
		ymtOrdersWapper.updateOrderAddtimeByOrderId(iOrder, 0);
		
		return iOrder;
	}
	
	
	
	//获取反库存 记录
	private static Map<String, Object> getReturnStockOperationLogMap(String productId) throws Exception{
		List<Map> stockOperationLogMapList = new StockOperationLogWapper().getAllByProductId(productId);
		 Logger.verifyEquals(2, stockOperationLogMapList.size(), "Mongo-库存记录个数");
		for(int i=0;i<stockOperationLogMapList.size();i++){
			if (Integer.parseInt(stockOperationLogMapList.get(i).get("StockNum").toString())>0){return stockOperationLogMapList.get(i);}
		}
		return null;
	}
	
	//获取反库存记录
	private static YmtProductOrderStockLog getReturnProductOrderStockLog(String productId) throws InterruptedException{
		List<YmtProductOrderStockLog >ymtProductOrderStockLogList = new YmtProductOrderStockLogWapper().selectByProductId(productId);
		Logger.verifyEquals(2, ymtProductOrderStockLogList.size(), "SQL-库存记录个数");
		for(YmtProductOrderStockLog y:ymtProductOrderStockLogList){
		  if (y.getStockNum()>0){return y; }
		}
		return null;
	}
}
